// 定义表示记分牌的类
class ScorePanel {
    score: number = 0;
    level: number = 1;
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    // 设置一个变量限制等级
    maxLevel: number;
    // 设置一个变量表示多少分升一级
    upScore: number;

    constructor(maxLevel: number, upScore: number) {
        this.scoreEle = document.getElementById('score')!;
        this.levelEle = document.getElementById('level')!;
        this.maxLevel = maxLevel;
        this.upScore = upScore;
    }

    addScore() {
        this.scoreEle.innerHTML = ++this.score + '';
        // 分数达到，自动升级
        if(this.score % this.upScore === 0){
            this.levelUp();
        }
    }
    levelUp() {
        if(this.level < this.maxLevel){
            this.levelEle.innerHTML = ++this.level + '';
        }
    }
}

// const scorePanel = new ScorePanel(100, 20);
// scorePanel.levelUp();
// console.log(scorePanel.level);

// scorePanel.addScore();
// console.log(scorePanel.score);
// scorePanel.addScore();
// console.log(scorePanel.score);


export default ScorePanel;